home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pccts
/
nesting.g
< prev
next >
Wrap
Text File
|
1993-07-19
|
1KB
|
50 lines
/* nesting.g
*
* example that uses DLG save and restore state functions to handle
* nested #include file specifications.
*
* Uses "fixed" version of dlgauto.h and dlgdef.h made available 2-26-93.
*
* Can create executable with:
*
* antlr nesting.g
* dlg -C2 parser.dlg scan.c
* cc -o nesting nesting.c err.c scan.c
*/
#header <<
#include "charbuf.h"
#define MAX_NESTING 10
extern struct dlg_state fstack[];
extern int fsp;
>>
<<
struct dlg_state fstack[MAX_NESTING];
int fsp=0;
main() { ANTLR(inc(), stdin); }
>>
#token "[\ \t]+" <<zzskip();>>
#token "\n" <<zzskip(); zzline++;>>
#token "@" <<if ( fsp>0 ) {
zzskip();
zzrestore_dlg_state(&fstack[--fsp]);
}
>>
inc : ( gunk )+
;
gunk: <<FILE *f;>>
( "[a-z]+" <<printf("%s\n", $1.text);>>
)+
| "#include" "\"" "[a-z]+" "\""
<<
zzsave_dlg_state(&fstack[fsp++]);
f = fopen($3.text, "r");
if ( f==NULL ) fprintf(stderr, "cannot open %s", $3.text);
zzrdstream(f);
>>
;